package co.fitstart.weapp.api.dao;

import java.util.List;

import com.demo2do.core.persistence.annotation.Dao;
import com.demo2do.core.persistence.annotation.Query;
import com.demo2do.core.persistence.annotation.Variable;

import co.fitstart.entity.user.User;
import co.fitstart.entity.user.UserAccount;
import co.fitstart.entity.user.WechatAccount;

/**
 * 
 * @author dan
 *
 */
@Dao("hibernate")
public interface UserDao {
    
    /**
     * 
     * @param unionid
     * @return
     */
    @Query("FROM User WHERE disabled = false AND unionid = :unionid")
    public User load(@Variable("unionid") String unionid);
    
    /**
     * 
     * @param mobile
     * @return
     */
    @Query("FROM User WHERE disabled = false AND mobile = :mobile")
    public User loadByMobile(@Variable("mobile") String mobile);

    /**
     * 
     * @param name
     * @param value
     * @return
     */
    @Query("FROM UserAccount userAccount WHERE userAccount.name = :name AND userAccount.value = :value")
    public UserAccount loadUserAccount(@Variable("name") String name, @Variable("value") String value);

    /**
     * 
     * @param openid
     * @param source
     * @return
     */
    @Query("FROM WechatAccount WHERE openid = :openid AND source = :source")
    public WechatAccount loadWechatAccount(@Variable("openid") String openid, @Variable("source") String source);

    /**
     * 
     * @param unionid
     * @return
     */
    @Query("FROM User WHERE disabled = false AND unionid = :unionid")
    public List<User> list(@Variable("unionid") String unionid);
}
